# Build recipe for perl-module-runtime.
#
# Copyright (c) 2018 Markus Tornow, <tornow@riseup.net>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=Module-Runtime
version=0.016
release=1

# Set 'outdir' for a nice and well-organized output directory
outdir="${outdir}/${arch}/modules/perl"

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=http://cpan.metacpan.org/authors/id/Z/ZE/ZEFRAM/"$tarname"

description="
Module::Runtime - runtime module handling.

The functions exported by this module deal with runtime handling of Perl
modules, which are normally handled at compile time. This module avoids
using any other modules, so that it can be used in low-level
infrastructure.

The parts of this module that work with module names apply the same
syntax that is used for barewords in Perl source. In principle this
syntax can vary between versions of Perl, and this module applies the
syntax of the Perl on which it is running. In practice the usable syntax
has not changed yet. There is some intent for Unicode module names to be
supported in the future, but this hasn't yet amounted to any consistent
facility.

The functions of this module whose purpose is to load modules include
workarounds for three old Perl core bugs regarding require. These
workarounds are applied on any Perl version where the bugs exist, except
for a case where one of the bugs cannot be adequately worked around in
pure Perl.
"

homepage=http://metacpan.org/pod/Module::Runtime
license="Artistic License"

# Source documentation
docs="Changes README SIGNATURE"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    perl Makefile.PL PREFIX=/usr
    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}/"
}


